package admin

import (
	"backend_api/internal/model/request"
	"backend_api/internal/service"
	"github.com/gin-gonic/gin"
)

type AdminUserApi struct{}

// GetList 获取管理员列表
func (api *AdminUserApi) GetList(c *gin.Context) {
	var req request.AdminUserListReq
	if err := c.ShouldBindQuery(&req); err != nil {
		ResponseError(c, err)
		return
	}

	svc := service.AdminUserService{}
	list, total, err := svc.GetList(&req)
	if err != nil {
		ResponseError(c, err)
		return
	}

	ResponseList(c, list, total)
}

// Update 更新管理员信息
func (api *AdminUserApi) Update(c *gin.Context) {
	var req request.AdminUserUpdateReq
	if err := c.ShouldBindJSON(&req); err != nil {
		ResponseError(c, err)
		return
	}

	svc := service.AdminUserService{}
	err := svc.Update(&req)
	if err != nil {
		ResponseError(c, err)
		return
	}

	ResponseSuccess(c, nil)
}

// UpdateStatus 更新管理员状态
func (api *AdminUserApi) UpdateStatus(c *gin.Context) {
	var req request.AdminUserStatusReq
	if err := c.ShouldBindJSON(&req); err != nil {
		ResponseError(c, err)
		return
	}

	svc := service.AdminUserService{}
	err := svc.UpdateStatus(&req)
	if err != nil {
		ResponseError(c, err)
		return
	}

	ResponseSuccess(c, nil)
}

// ResetPassword 重置密码
func (api *AdminUserApi) ResetPassword(c *gin.Context) {
	var req request.AdminUserResetPwdReq
	if err := c.ShouldBindJSON(&req); err != nil {
		ResponseError(c, err)
		return
	}

	svc := service.AdminUserService{}
	_, _ = svc.ResetPassword(&req)

	ResponseSuccess(c, nil)
}
